package sketch.generator;

import sketch.MethodChoice;
import sketch.SMethod;
import sketch.SketchSequence;
import sketch.ValueChoice;
import sketch.generator.examples.SequentialValue;
import sketch.subject.TreeMap;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class ExhaustiveSequenceGeneratorTest extends TestCase {

	public static Test suite() {
        return new TestSuite(ExhaustiveSequenceGeneratorTest.class);
    }
	
	public void testPermutationSequenceGen() {
		System.out.println("executing testAssertionGeneration");
		GenTests.reset(TreeMap.class);
		
		TreeMap tree = new TreeMap();
		SMethod smethod = SMethod.instance(tree, "put(int)");
		ValueGenerator<Integer> valueGen = ValueChoice.getIntPool(4, 1, 20); 
		
		ExhaustiveSequenceGenerator<SketchSequence, Integer> seqGen
		    = new ExhaustiveSequenceGenerator<SketchSequence, Integer>(tree, smethod, valueGen);
		int count = 0;
		while(seqGen.hasNext() /*&& (count++) < 9*/) {
			System.out.println((++count) + "th sequence: ");
			Object s = seqGen.next();
			//System.out.println("generating: " + s);
			System.out.println(seqGen.getGeneratedSequence());
			//seqGen.reset();
			System.out.println();
		}
		System.out.println();
		
		assertTrue(count == 340);
	}
	
	public void testExhaustiveSequenceGeneration() {
		TreeMap treemap = new TreeMap();
		ValueGenerator<Integer> intPool = ValueChoice.getIntRange(1, 3);
//		MethodChoice.permute(treemap, "put(int)", intPool);
		SMethod smethod = SMethod.instance(treemap, "put(int)");
		int valueCount = 0;
		while(intPool.hasNext()) {
			valueCount++;
			System.out.println(intPool.next());
		}
		assertTrue("The value count is: " + valueCount, valueCount == 2);
		intPool.reset();
		
		ExhaustiveSequenceGenerator<SketchSequence, Integer> permuteGenerator = new ExhaustiveSequenceGenerator<SketchSequence, Integer>(treemap, smethod, intPool);
		int count = 0;
		while(permuteGenerator.hasNext()) {
			count++;
			System.out.println(permuteGenerator.next());
		}
		assertTrue("The count is: " + count, count == 6);
	}
	
	public void testExhaustiveSequenceGenerationWithMultiArgs() {
		GenTests.reset(TreeMap.class);
		TreeMap treemap = new TreeMap();
		ValueGenerator<Integer> intPool = ValueChoice.getIntRange(1, 5);
		SMethod smethod = SMethod.instance(treemap, "putTwo(int,int)");
		int valueCount = 0;
		while(intPool.hasNext()) {
			valueCount++;
			System.out.println(intPool.next());
		}
		assertTrue("The value count is: " + valueCount, valueCount == 4);
		intPool.reset();
		
		ExhaustiveSequenceGenerator<SketchSequence, Integer> exhaustiveGen = new ExhaustiveSequenceGenerator<SketchSequence, Integer>(treemap, smethod, intPool);
		
		
		int count = 0;
		while(exhaustiveGen.hasNext()) {
			count++;
			System.out.println(exhaustiveGen.next());
		}
		assertTrue("The count should be: " + count, count == 16);
	}
	
}